-
Notifications
You must be signed in to change notification settings - Fork 738
refactor(fs): prefer our fs and fs to fs-extra (pt1: non-test files) #5689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
This pull request modifies code in src/ but no tests were added/updated. Confirm whether tests should be added or ensure the PR description explains why tests are not required. |
|
/retryBuilds |
| config.eventPayloadFile === undefined | ||
| ? undefined | ||
| : JSON.parse(await readFile(config.eventPayloadFile, { encoding: 'utf-8' })) | ||
| : JSON.parse(await fs.readFileAsString(config.eventPayloadFile)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
off-topic: we should rename this function :)
| : JSON.parse(await fs.readFileAsString(config.eventPayloadFile)) | |
| : JSON.parse(await fs.readFileText(config.eventPayloadFile)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, its not obvious that its auto-converting the file bytes to text. I'll track it, and can do this in a follow up. I think there's enough going on in this PR.
| await fs.appendFile(sshConfigPath, section, { mode: 0o600 }) | ||
| const parentsDir = path.dirname(sshConfigPath) | ||
| const grandParentsDir = path.dirname(parentsDir) | ||
| // TODO: replace w/ fs.chmod once stub is merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#5647 is ready to merge
| fs.copySync(path.join(tempPath, 'usr', 'local', 'sessionmanagerplugin'), outDir, { | ||
| recursive: true, | ||
| }) | ||
| await fs.copy(path.join(tempPath, 'usr', 'local', 'sessionmanagerplugin'), outDir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fs.copy needs a docstring, it's not obvious that it also supports folders.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tracked as a followup, seems like there a few other methods that could use them as well in fs.
justinmk3
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Co-authored-by: Justin M. Keyes <[email protected]>
|
@aws/dexp @aws/codewhisperer-team |
## Problem In the recent refactor (#5689), there is a mismatch in args between our fs and fs-extra. Not caught until integ tests were run. ## Solution have default write file method ignores encoding since it uses utf8 anyway. --- <!--- REMINDER: Ensure that your PR meets the guidelines in CONTRIBUTING.md --> License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
## Problem Follow up from #5689, focusing on the test files. ## Solution Mostly direct translation, one implementation change from `writeJson` to `Json.stringify` then `writeFile` in `packages/core/src/test/awsService/cdk/detectCdkProjects.test.ts` line 120 --- <!--- REMINDER: Ensure that your PR meets the guidelines in CONTRIBUTING.md --> License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
…gs (#5713) ## Problem Follow up from: #5689 ## Solution - rename 'readFileAsString' to 'readFileText' since this function assumes a text file (utf-8) encoding. - Add missing doc strings to copy and exist within fs wrapper. --- <!--- REMINDER: Ensure that your PR meets the guidelines in CONTRIBUTING.md --> License: I confirm that my contribution is made under the terms of the Apache 2.0 license. --------- Co-authored-by: Justin M. Keyes <[email protected]>
Problem
We want to avoid fs-extra, and eventually move it to the banned import list. As a first step, we remove fs-extra with as much of our own
fs.tswork, andfswhen not possible.This PR only works on non-testing code. This way we can ensure our tests are not compromised, and still show that our code exhibits the desired behavior.
Solution
Indirect Translations
ensureDirwithmkDiras suggested here: https://github.com/jprichardson/node-fs-extra/blob/HEAD/docs/ensureDir.mdensureDirwith permissions arg can bemkDirwithchmodfollowing.movewithrenamesince we aren't using virtual file system, or crossing disk partitions: https://stackoverflow.com/questions/8579055/how-do-i-move-files-in-node-jsOtherwise the translations are fairly direct.
Notes
As of 9/30 there is a tech debt test failing blocking potential merge. This test was pushed back to 10/30.
License: I confirm that my contribution is made under the terms of the Apache 2.0 license.